Android Game Recipes: A Problem-Solution Approach by Jerome Dimarzio

Android Game Recipes: A Problem-Solution Approach by Jerome Dimarzio

Author:Jerome Dimarzio [Dimarzio, Jerome]
Language: eng
Format: epub, mobi
Tags: Computers, Programming, Games, Hardware, Mobile Devices
ISBN: 9781430257646
Google: 0ipsmwEACAAJ
Amazon: 1430257644
Publisher: Apress
Published: 2013-10-23T04:00:00+00:00


7.2 Scroll the Background Horizontally

Problem

The background is currently static, and it should scroll horizontally.

Solution

Create a new class in the game loop that translates the background texture a set amount on the y axis.

How It Works

The first step in the OpenGL ES 1 version of this solution is to create two variables that will be used to track the current location of the background texture and the value by which to translate the texture, respectively.

int bgScroll1 = 0;

float SCROLL_BACKGROUND_1 = .002f;

These variables can be local to your Renderer class, or you can store them in a separate class.

The onDrawFrame() method, within an implementation of an OpenGL ES Renderer, is called on every iteration of the game loop. You need to create a new method, called scrollBackground(), that is in turn called from the onDrawFrame() method (see Listing 7-5).

Listing 7-5. scrollBackground() (OpenGL ES 1)

private void scrollBackground1(GL10 gl){

if (bgScroll1 == Float.MAX_VALUE){

bgScroll1 = 0f;

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.